#include <func.h>

int mkdirClient(int netfd, char *workdir, char *PathToMkdir)
{
    if (PathToMkdir == NULL)
    {
        puts("please input the path!");
        return -1;
    }
    //发送要创建的目录路径
    char absPath[512] = {0};
    int ret = getAbsPath(workdir, PathToMkdir, absPath);
    if (ret == -1)
    {
        puts("error path, please check your input and try angin!");
        return -1;
    }

    int datalen = strlen(absPath);
    ret = send(netfd, &datalen, sizeof(datalen), 0);
    ERROR_CHECK(ret, -1, "send absPath datalen in mkdirClient");
    ret = send(netfd, absPath, datalen, 0);
    ERROR_CHECK(ret, -1, "send absPath dataInfor in mkdirClient");
    //接受反馈信息
    int failFlag;
    recvn(netfd, &failFlag, sizeof(failFlag));
    //如果失败了
    if (failFlag == 1)
    {
        printf("cannot find the path:%s, please check your input!\n", absPath);
        return -1;
    }
    //成功了
    printf("mkdir %s success!\n", absPath);
    return 0;
}